package cloud.service.user.service;


import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;

import cloud.service.user.dao.UserDao;
import cloud.service.user.model.User;



@Service
@Transactional
public class UserService {

	
	@Autowired
	private UserDao userMapper;
	
	public List<User> searchAll(){
		List<User> list = userMapper.findAll();
		return list;
	}
	
	@HystrixCommand(fallbackMethod = "fallback")
	public List<User> throwException(){
		String[] s = new String[]{};
		System.err.println(s[1]);
		return new ArrayList<>();
	}
	
	public List<User> fallback(){
		List<User> list = new  ArrayList<>();
		User user = new User();
		user.setUsername("Hystrix-Error");
		list.add(user);
		return list;
	}
}
